package com.ttms.dao.impl;

import com.ttms.dao.ScheduleDao;
import com.ttms.pojo.Schedule;

import java.math.BigDecimal;
import java.util.List;

public class ScheduleDaoImpl extends BaseDao implements ScheduleDao {
    @Override
    public int addSchedule(Schedule schedule) {
        String sql = "insert into schedule(`studio_id` ,`play_id`, `sched_time`, `sched_ticket_price` ) values(?,?,?,?)";
        return update(sql, schedule.getStudio_id(),schedule.getPlay_id(),schedule.getSched_time(),schedule.getSched_ticket_price());
    }

    @Override
    public int deleteScheduleById(Integer id) {
        String sql = "delete from schedule where sched_id = ?";
        return update(sql, id);
    }

    @Override
    public int updateSchedule(Schedule schedule) {
        String sql = "update schedule set `studio_id`=?  ,`play_id`=? , `sched_time`=? , `sched_ticket_price`=? where sched_id = ?";
        return update(sql, schedule.getStudio_id(),schedule.getPlay_id(),schedule.getSched_time(),schedule.getSched_ticket_price(),schedule.getSched_id());
    }

    @Override
    public Schedule queryScheduleById(Integer id) {
        String sql = "select * from schedule where sched_id = ?";
        return queryForOne(Schedule.class, sql,id);
    }

    @Override
    public List<Schedule> querySchedules() {
        String sql = "select * from schedule";
        return queryForList(Schedule.class, sql);
    }

    @Override
    public Integer queryForPageTotalCount() {
        String sql = "select count(*) from schedule";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }

    @Override
    public List<Schedule> queryForPageItems(int begin, int pageSize) {
        String sql = "select * from schedule limit ?,?";
        return queryForList(Schedule.class,sql,begin,pageSize);
    }

    @Override
    public List<Schedule> queryScheduleByPlayId(int begin, int pageSize, int id) {
        String sql = "select * from schedule where play_id ="+ id +" order by sched_id limit ?,?";
        return queryForList(Schedule.class,sql,begin,pageSize);
    }

    @Override
    public Integer queryScheduleCountByPlayId(int id) {
        String sql = "select count(*) from schedule where play_id = "+ id;
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }
}
